package com.easyj.admin.db.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import com.easyj.base.cache.SysCacheUtil;



/**
 *   @title 用户
 *   @remark 
 *   @table b_user
 *   @primaryKey id
 *   @enablePage true
 *   @uniqueIndex selectUniqueByUqLoginName(loginName)
 *   @uniqueIndex selectUniqueByUqName(name)
 */
public class User implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     *   @title 用户表
     *   @remark 
     *   @column id
     *   @dataType BIGINT
     *   @length 19
     *   @scale 0
     *   @nullable false
     *   @jdbcType BIGINT
     */
    @NotNull(groups = Update.class)
    private Long id;

    /**
     *   @title 登录账号
     *   @remark 工厂一般是工号。唯一
     *   @column login_name
     *   @dataType VARCHAR
     *   @length 50
     *   @scale 0
     *   @nullable false
     *   @jdbcType VARCHAR
     */
    @NotBlank(groups = Create.class)
    private String loginName;

    /**
     *   @title 密码
     *   @remark 
     *   @column password
     *   @dataType VARCHAR
     *   @length 120
     *   @scale 0
     *   @nullable false
     *   @jdbcType VARCHAR
     */
    @NotBlank(groups = Create.class)
    private String password;

    /**
     *   @title 真实姓名
     *   @remark 
     *   @column name
     *   @dataType VARCHAR
     *   @length 60
     *   @scale 0
     *   @nullable false
     *   @jdbcType VARCHAR
     */
    @NotBlank(groups = {Create.class,Update.class},message= "{user.name}")
    private String name;

    /**
     *   @title 性别
     *   @remark 1-男，2，女，
     *   @column sex
     *   @dataType SMALLINT
     *   @length 5
     *   @scale 0
     *   @nullable true
     *   @jdbcType SMALLINT
     */
    private Short sex;

   
    /**
     *   @title 
     *   @remark 
     *   @column avatar
     *   @dataType VARCHAR
     *   @length 100
     *   @scale 0
     *   @nullable true
     *   @jdbcType VARCHAR
     */
    private String avatar;

    /**
     *   @title 
     *   @remark 
     *   @column email
     *   @dataType VARCHAR
     *   @length 200
     *   @scale 0
     *   @nullable true
     *   @jdbcType VARCHAR
     */
    @Email(groups = {Create.class,Update.class})
    private String email;

    /**
     *   @title 联系电话
     *   @remark 
     *   @column telephone
     *   @dataType VARCHAR
     *   @length 45
     *   @scale 0
     *   @nullable true
     *   @jdbcType VARCHAR
     */
    private String telephone;

    /**
     *   @title 手机号码
     *   @remark 
     *   @column mobile
     *   @dataType VARCHAR
     *   @length 45
     *   @scale 0
     *   @nullable true
     *   @jdbcType VARCHAR
     */
    private String mobile;

    /**
     *   @title 
     *   @remark 
     *   @column address
     *   @dataType VARCHAR
     *   @length 200
     *   @scale 0
     *   @nullable true
     *   @jdbcType VARCHAR
     */
    private String address;

    /**
     *   @title QQ号
     *   @remark 
     *   @column qq
     *   @dataType VARCHAR
     *   @length 45
     *   @scale 0
     *   @nullable true
     *   @jdbcType VARCHAR
     */
    private String qq;

    /**
     *   @title 
     *   @remark 
     *   @column weixin
     *   @dataType VARCHAR
     *   @length 45
     *   @scale 0
     *   @nullable true
     *   @jdbcType VARCHAR
     */
    private String weixin;

    /**
     *   @title 部们
     *   @remark 
     *   @column department_id
     *   @dataType BIGINT
     *   @length 19
     *   @scale 0
     *   @nullable false
     *   @jdbcType BIGINT
     */
    @NotNull(groups = {Create.class,Update.class})
    private Long departmentId;

    /**
     *   @title 职务
     *   @remark 
     *   @column duty
     *   @dataType VARCHAR
     *   @length 50
     *   @scale 0
     *   @nullable true
     *   @jdbcType VARCHAR
     */
    private String duty;

    /**
     *   @title 状态
     *   @remark 0-停用，1-正常
     *   @column status
     *   @dataType INT
     *   @length 10
     *   @scale 0
     *   @nullable false
     *   @jdbcType INTEGER
     */
    @NotNull(groups = {Create.class,Update.class},message= "{user.status}")
    private Integer status;

    /**
     *   @title 操作人
     *   @remark 
     *   @column operator_id
     *   @dataType BIGINT
     *   @length 19
     *   @scale 0
     *   @nullable true
     *   @jdbcType BIGINT
     */
    private Long operatorId;

    /**
     *   @title 修改时间
     *   @remark 
     *   @column modify_time
     *   @dataType DATETIME
     *   @length 19
     *   @scale 0
     *   @nullable true
     *   @jdbcType TIMESTAMP
     */
    private Date modifyTime;

    /**
     *   @title 创建时间
     *   @remark 
     *   @column create_time
     *   @dataType DATETIME
     *   @length 19
     *   @scale 0
     *   @nullable true
     *   @jdbcType TIMESTAMP
     */
    private Date createTime;

    /**
     *   @title 是否系统预定义
     *   @remark 
     *   @column is_system
     *   @dataType BIT
     *   @length 1
     *   @scale 0
     *   @nullable false
     *   @jdbcType BIT
     */
    private Boolean isSystem;

    /**
     *   @title 登录ip
     *   @remark 
     *   @column login_ip
     *   @dataType VARCHAR
     *   @length 128
     *   @scale 0
     *   @nullable true
     *   @jdbcType VARCHAR
     */
    private String loginIp;

    /**
     *   @title 登录时间
     *   @remark 
     *   @column login_time
     *   @dataType DATETIME
     *   @length 19
     *   @scale 0
     *   @nullable true
     *   @jdbcType TIMESTAMP
     */
    private Date loginTime;

    /**
     *   @title 是否登录成功
     *   @remark 
     *   @column login_success
     *   @dataType BIT
     *   @length 1
     *   @scale 0
     *   @nullable true
     *   @jdbcType BIT
     */
    private Boolean loginSuccess;

    /**
     *   @title 登录失败次数
     *   @remark 
     *   @column login_err_count
     *   @dataType INT
     *   @length 10
     *   @scale 0
     *   @nullable true
     *   @jdbcType INTEGER
     */
    private Integer loginErrCount;

    /**
     *   @title 入职日期
     *   @remark 
     *   @column jionday
     *   @dataType DATETIME
     *   @length 19
     *   @scale 0
     *   @nullable true
     *   @jdbcType TIMESTAMP
     */
    private Date jionday;

    /**
     *   @title 职位级别
     *   @remark 
     *   @column level
     *   @dataType INT
     *   @length 10
     *   @scale 0
     *   @nullable true
     *   @jdbcType INTEGER
     */
    private Integer level;

    /**
     *   @title 是否锁定
     *   @remark 
     *   @column locked
     *   @dataType BIT
     *   @length 1
     *   @scale 0
     *   @nullable false
     *   @jdbcType BIT
     */
    private Boolean locked;

    /**
     *   @title 证件号
     *   @remark 
     *   @column id_no
     *   @dataType VARCHAR
     *   @length 45
     *   @scale 0
     *   @nullable true
     *   @jdbcType VARCHAR
     */
    private String idNo;

    /**
     *   @title 证件类型
     *   @remark 
     *   @column id_type
     *   @dataType VARCHAR
     *   @length 45
     *   @scale 0
     *   @nullable true
     *   @jdbcType VARCHAR
     */
    private String idType;

   
    /**
     *   @title 职位状态
     *   @remark 
     *   @column state
     *   @dataType INT
     *   @length 10
     *   @scale 0
     *   @nullable false
     *   @jdbcType INTEGER
     */
    @NotNull(groups = {Create.class,Update.class},message= "{user.state}")
    private Integer state;

    /**
     *   @title 出生日期
     *   @remark 
     *   @column birthday
     *   @dataType DATE
     *   @length 10
     *   @scale 0
     *   @nullable true
     *   @jdbcType DATE
     */
    private Date birthday;

    /**
     *   @title 学历
     *   @remark 
     *   @column edu_level
     *   @dataType VARCHAR
     *   @length 40
     *   @scale 0
     *   @nullable true
     *   @jdbcType VARCHAR
     */
    private String eduLevel;

    /**
     *   @title 毕业院校
     *   @remark 
     *   @column grade_school
     *   @dataType VARCHAR
     *   @length 100
     *   @scale 0
     *   @nullable true
     *   @jdbcType VARCHAR
     */
    private String gradeSchool;

    /**
     *   @title 毕业时间
     *   @remark 
     *   @column grade_day
     *   @dataType DATE
     *   @length 10
     *   @scale 0
     *   @nullable true
     *   @jdbcType DATE
     */
    private Date gradeDay;
    
    
    /**
     *   @title 关联emp_id
     *   @remark 
     *   @column emp_id
     *   @dataType BIGINT
     *   @length 19
     *   @scale 0
     *   @nullable true
     *   @jdbcType BIGINT
     */
    private Long empId;

    /**
     *   @title 工号
     *   @remark 备用
     *   @column woker_no
     *   @dataType VARCHAR
     *   @length 50
     *   @scale 0
     *   @nullable true
     *   @jdbcType VARCHAR
     */
    private String wokerNo;
    
    /**
     * @title 拥有的角色
     */
    private List<Role> roles;
    
    private List<Long> roleIds;
    
    private List<Position> positions;
    
    private List<Long> positionIds;
    
    private String rolesName;
    private String positionsName;
    
   
    /**
     * 
     * @return 状态
     */
    public String getStateName() {
    	if(state==1) {
    		return "在职";
    	}else if(state==0) {
    		return "离职";
    	}else {
    		return "非法值："+state;
    	}
    }
    
    public String getDepartmentName(){
    	return SysCacheUtil.getDepartmentName(departmentId);
    }
    
   
    
    public String getOperatorName() {
       	return SysCacheUtil.getOperatorName(operatorId);
   	} 

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Short getSex() {
        return sex;
    }

    public void setSex(Short sex) {
        this.sex = sex;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getQq() {
        return qq;
    }

    public void setQq(String qq) {
        this.qq = qq;
    }

    public String getWeixin() {
        return weixin;
    }

    public void setWeixin(String weixin) {
        this.weixin = weixin;
    }

    public Long getDepartmentId() {
        return departmentId;
    }

    public void setDepartmentId(Long departmentId) {
        this.departmentId = departmentId;
    }

    public String getDuty() {
        return duty;
    }

    public void setDuty(String duty) {
        this.duty = duty;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Long getOperatorId() {
        return operatorId;
    }

    public void setOperatorId(Long operatorId) {
        this.operatorId = operatorId;
    }

    public Date getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Boolean getIsSystem() {
        return isSystem;
    }

    public void setIsSystem(Boolean isSystem) {
        this.isSystem = isSystem;
    }

    public String getLoginIp() {
        return loginIp;
    }

    public void setLoginIp(String loginIp) {
        this.loginIp = loginIp;
    }

    public Date getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(Date loginTime) {
        this.loginTime = loginTime;
    }

    public Boolean getLoginSuccess() {
        return loginSuccess;
    }

    public void setLoginSuccess(Boolean loginSuccess) {
        this.loginSuccess = loginSuccess;
    }

    public Integer getLoginErrCount() {
        return loginErrCount;
    }

    public void setLoginErrCount(Integer loginErrCount) {
        this.loginErrCount = loginErrCount;
    }

    public Date getJionday() {
        return jionday;
    }

    public void setJionday(Date jionday) {
        this.jionday = jionday;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public Boolean getLocked() {
        return locked;
    }

    public void setLocked(Boolean locked) {
        this.locked = locked;
    }

    public String getIdNo() {
        return idNo;
    }

    public void setIdNo(String idNo) {
        this.idNo = idNo;
    }

    public String getIdType() {
        return idType;
    }

    public void setIdType(String idType) {
        this.idType = idType;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getEduLevel() {
        return eduLevel;
    }

    public void setEduLevel(String eduLevel) {
        this.eduLevel = eduLevel;
    }

    public String getGradeSchool() {
        return gradeSchool;
    }

    public void setGradeSchool(String gradeSchool) {
        this.gradeSchool = gradeSchool;
    }

    public Date getGradeDay() {
        return gradeDay;
    }

    public void setGradeDay(Date gradeDay) {
        this.gradeDay = gradeDay;
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        User other = (User) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()));
    }

    
    public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	public List<Long> getRoleIds() {
		return roleIds;
	}

	public void setRoleIds(List<Long> roleIds) {
		this.roleIds = roleIds;
	}


	public Long getEmpId() {
		return empId;
	}

	public void setEmpId(Long empId) {
		this.empId = empId;
	}

	public String getWokerNo() {
		return wokerNo;
	}

	public void setWokerNo(String wokerNo) {
		this.wokerNo = wokerNo;
	}

	@Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        return result;
    }
	
	

    public List<Position> getPositions() {
		return positions;
	}

	public void setPositions(List<Position> positions) {
		this.positions = positions;
	}

	public List<Long> getPositionIds() {
		return positionIds;
	}

	public void setPositionIds(List<Long> positionIds) {
		this.positionIds = positionIds;
	}

	public String getRolesName() {
		return rolesName;
	}

	public void setRolesName(String rolesName) {
		this.rolesName = rolesName;
	}

	public String getPositionsName() {
		return positionsName;
	}

	public void setPositionsName(String positionsName) {
		this.positionsName = positionsName;
	}

	@Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append(", id=").append(id);
        sb.append(", loginName=").append(loginName);
        sb.append(", password=").append(password);
        sb.append(", name=").append(name);
        sb.append(", sex=").append(sex);
        sb.append(", avatar=").append(avatar);
        sb.append(", email=").append(email);
        sb.append(", telephone=").append(telephone);
        sb.append(", mobile=").append(mobile);
        sb.append(", address=").append(address);
        sb.append(", qq=").append(qq);
        sb.append(", weixin=").append(weixin);
        sb.append(", departmentId=").append(departmentId);
        sb.append(", duty=").append(duty);
        sb.append(", status=").append(status);
        sb.append(", operatorId=").append(operatorId);
        sb.append(", modifyTime=").append(modifyTime);
        sb.append(", createTime=").append(createTime);
        sb.append(", isSystem=").append(isSystem);
        sb.append(", loginIp=").append(loginIp);
        sb.append(", loginTime=").append(loginTime);
        sb.append(", loginSuccess=").append(loginSuccess);
        sb.append(", loginErrCount=").append(loginErrCount);
        sb.append(", jionday=").append(jionday);
        sb.append(", level=").append(level);
        sb.append(", locked=").append(locked);
        sb.append(", idNo=").append(idNo);
        sb.append(", idType=").append(idType);
        sb.append(", state=").append(state);
        sb.append(", birthday=").append(birthday);
        sb.append(", eduLevel=").append(eduLevel);
        sb.append(", gradeSchool=").append(gradeSchool);
        sb.append(", gradeDay=").append(gradeDay);
        sb.append("]");
        return sb.toString();
    }
	
	public @interface Update {}
	public @interface Create {}
}